import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:marquee/marquee.dart';

import 'home_cubit.dart';
import 'home_state.dart';

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (BuildContext context) => HomeCubit(),
      child: Builder(builder: (context) => _buildPage(context)),
    );
  }

  Widget _buildPage(BuildContext context) {
    final cubit = BlocProvider.of<HomeCubit>(context);

    return Scaffold(
        backgroundColor: Colors.black,
        body: GestureDetector(
          onScaleStart: cubit.onScaleStart,
          onScaleUpdate: cubit.onScaleUpdate,
          onTap: (){
            cubit.showIOSDialog(context);
          },
          child: BlocBuilder<HomeCubit,HomeState>(
            builder: (context,state){
              return Transform.scale(
                scale: state.scale,
                child: SizedBox(
                  width: double.infinity,
                  height: double.infinity, // 设置固定高度以限制文字的放大缩小范围
                  child: Marquee(
                    text: state.txt.isNotEmpty?state.txt:"Johnny",
                    style: TextStyle(fontSize: 20.0,color: state.currentColor),
                    scrollAxis: Axis.horizontal,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    blankSpace: 20,
                    velocity: state.speed,
                    startPadding: 0.0,
                  ),
                ),
              );
            },

          ) ,
        ));
  }
}
